package cn.yunhe.Interceptor;

import cn.yunhe.entity.User;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;

import java.util.Map;

public class UserInterceptor extends MethodFilterInterceptor {
    @Override
    protected String doIntercept(ActionInvocation invocation) throws Exception {
        Map session = invocation.getInvocationContext().getSession();
        Map request = (Map) invocation.getInvocationContext().get("request");
        User user = (User) session.get("user");
        if (user == null) {
            request.put("result", "您暂未登录或登录已经失效,请<a href='/login.jsp'>登录</a>");
            return "error";
        } else {
            return invocation.invoke();
        }
    }
}
